package cn.iocoder.yudao.module.member.assets.controller.app;

import cn.iocoder.yudao.framework.business.basic.controller.PageController;
import cn.iocoder.yudao.framework.business.basic.controller.SimpleDetailController;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.member.assets.service.AppCryptocurrencyIncreasingTaskService;
import cn.iocoder.yudao.module.member.assets.vo.AppCryptocurrencyIncreasingTakeAdRespVO;
import cn.iocoder.yudao.module.member.assets.vo.AppCryptocurrencyIncreasingTaskQueryDTO;
import cn.iocoder.yudao.module.member.assets.vo.AppCryptocurrencyIncreasingTaskSubmitVO;
import cn.iocoder.yudao.module.member.assets.vo.AppCryptocurrencyIncreasingTaskVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;

@Tag(name = "用户 App - 数字资产")
@RestController
@RequestMapping("/member/cryptocurrency-increment")
@Validated
public class AppCryptocurrencyIncreasingTaskController implements SimpleDetailController<AppCryptocurrencyIncreasingTaskVO>, PageController<AppCryptocurrencyIncreasingTaskVO, AppCryptocurrencyIncreasingTaskQueryDTO> {
    @Resource
    private AppCryptocurrencyIncreasingTaskService appCryptocurrencyIncreasingTaskService;

    @Operation(summary = "联盟豆增值任务详情")
    @Override
    public CommonResult<AppCryptocurrencyIncreasingTaskVO> getDetail(Long id) {
        return success(appCryptocurrencyIncreasingTaskService.getDetail(id, getLoginUserId()));
    }

    @Operation(summary = "联盟豆增值任务分页")
    @Override
    public CommonResult<PageResult<AppCryptocurrencyIncreasingTaskVO>> getPage(Integer pageNo, Integer pageSize, AppCryptocurrencyIncreasingTaskQueryDTO param) {
        return success(appCryptocurrencyIncreasingTaskService.getPage(pageNo, pageSize, param, getLoginUserId()));
    }

    @GetMapping("/available")
    @Operation(summary = "联盟豆增值任务获取可用的一条", description = "联盟豆增值任务如果有多个，则合并为一个返回")
    CommonResult<AppCryptocurrencyIncreasingTaskVO> getAvailable() {
        return success(appCryptocurrencyIncreasingTaskService.getAvailable(getLoginUserId()));
    }

    @PostMapping("/take")
    @Operation(summary = "联盟豆增值任务领取广告", description = "目前是随机取一个，后续应该需要针对性搞专门的广告推荐算法")
    CommonResult<AppCryptocurrencyIncreasingTakeAdRespVO> takeAd() {
        return success(appCryptocurrencyIncreasingTaskService.takeAd(getLoginUserId()));
    }

    @PostMapping("/submit")
    @Operation(summary = "联盟豆增值任务提交")
    CommonResult<Boolean> submit(@Valid @RequestBody AppCryptocurrencyIncreasingTaskSubmitVO param) {
        appCryptocurrencyIncreasingTaskService.submit(param, getLoginUserId());
        return success(true);
    }

}